package cn.jy.boot.bean;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/*
* 解析国际化信息
* */
public class MylocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        //获取语言信息
        String lang = request.getParameter("lang");
        //获取local对象
        Locale locale = request.getLocale();
        //zh_CN
        if (!StringUtils.isEmpty(lang)){
//            截取 语言信息和 地域信息
            String[] strArr = lang.split("_");
            //创建Local 对象 赋值给Local
            locale = new Locale(strArr[0],strArr[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
